﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAO;
using DTO;
namespace BUS
{
    public class ProviderBUS
    {
        /// <summary>
        /// lay tat ca danh sach cac Provider
        /// </summary>
        /// <returns></returns>
        public static List<PROVIDER> GetAllProvider()
        {
            try
            {
                return ProviderDAO.GetAllProvider();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static bool Insert(PROVIDER Provider)
        {
            try
            {
                Provider.ACCOUNT.ACCOUNT_STYLE = false;
                Provider.ACCOUNT.VISIBLE = true;
                return ProviderDAO.Insert(Provider);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        /// <summary>
        /// update 1 Provider
        /// </summary>
        /// <param name="Provider"></param>
        /// <returns></returns>
        public static bool Update(PROVIDER Provider)
        {
            try
            {
                bool isExist = ProviderDAO.isExisting(Provider.IDPROVIDER);
                if (!isExist)
                    return false;
                return ProviderDAO.Update(Provider);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public static PROVIDER GetProvider(string UserName, string PassWord)
        {
            try
            {
                bool isExist = ProviderDAO.isExisting(UserName, PassWord);
                if (!isExist)
                    return null;
                return ProviderDAO.GetProvider(UserName, PassWord);
            }
            catch (Exception ex)
            {
                throw ex;
            }

        }

        public static PROVIDER GetProvider(string UserName)
        {
            try
            {
                bool isExist = ProviderDAO.isExisting(UserName);
                if (!isExist)
                    return null;
                return ProviderDAO.GetProvider(UserName);
            }
            catch (Exception ex)
            {
                throw ex;
            }

        }

        public static PROVIDER GetProviderFromAccount(int idAccount)
        {
            try
            {
                return ProviderDAO.GetProviderFromAccount(idAccount);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }


        public static PROVIDER GetProvider(int idProvider)
        {
            try
            {
                bool isExist = ProviderDAO.isExisting(idProvider);
                if (!isExist)
                    return null;
                return ProviderDAO.GetProvider(idProvider);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public static bool Delete(int idProvider)
        {
            try
            {
                bool isExist = ProviderDAO.isExisting(idProvider);
                if (!isExist)
                    return false;
                return ProviderDAO.Delete(idProvider);
            }
            catch(Exception ex)
            {
                throw ex;
            }
        }

        public static int GetIDProvider(string companyName)
        {
            try
            {
                return ProviderDAO.GetIDProvider(companyName);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

    }
}
